//
//  ST_BaseViewController.m
//  ST_BaseMall
//
//  Created by 昱胜 on 2022/9/2.
//

#import "ST_BaseViewController.h"
#import "ST_LoadView.h"

@interface ST_BaseViewController ()<UIGestureRecognizerDelegate>

@end

@implementation ST_BaseViewController

- (void)dealloc{
    [self dissmissLoadingView];
    NSLog(@"%s", __FUNCTION__);
    NSLog(@"%@", self.class);
}
- (void)viewDidLoad {
    [super viewDidLoad];
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
        [self setEdgesForExtendedLayout:UIRectEdgeNone];
    }
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = [UIColor appBGColor];
    self.navigationController.interactivePopGestureRecognizer.delegate=(id)self;
    self.fd_interactivePopDisabled = NO;
    self.fd_prefersNavigationBarHidden = NO;
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDarkContent animated:NO];
    
    //修改电池栏颜色
    [self setNeedsStatusBarAppearanceUpdate];
    //关闭夜间模式
    if (@available(iOS 13.0, *)) {
        self.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
    } else {
        // Fallback on earlier versions
    }
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self setKeyBoardDismiss];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}

- (void)showNavTitle:(NSString *)title {
    [self showNavTitle:title showLeftItem:YES];
}

- (void)showNavTitle:(NSString *)title showLeftItem:(BOOL)show {
    ST_NavView *nav = [[ST_NavView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kNavBarAndStatusBarHeight)];
    self.navView = nav;
    nav.backgroundColor = [UIColor appWhiteLabelColor];
    [self.view addSubview:nav];
    
    nav.leftButton.hidden = !show;
    
    nav.titleLabel.text = title;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}

#pragma mark UIGestureRecognizerDelegate
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    return YES ;
}
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleDefault;
}
- (BOOL)shouldAutorotate {
    return NO;
}
- (BOOL)prefersStatusBarHidden {
    return NO;
}
//返回支持的方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}
//这个是返回优先方向
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

- (void)showLoadingView {
    [[ST_LoadView shareEmptyView]show];
}

- (void)dissmissLoadingView {
    [[ST_LoadView shareEmptyView]dismiss];
}


@end
